from Page.Page1 import Page1
from Page.Page2 import Page2
from selenium import webdriver
from Run.logger import login
import logging
import pytest


@pytest.fixture()
def driver():
    driver = webdriver.Edge()
    driver.maximize_window()
    login()
    yield driver
    driver.close()

class Test_case():
    def test_a3mall_login_001(self,driver):
        # 正确捕获业务逻辑异常并记录日志。
        logging.debug('start')
        po = Page1(driver)
        po.a3mall_login_001()
        logging.debug('last')


    # 正确抛出数据访问异常（如数据库连接超时）。
    def test_a3mall_login_002(self, driver):
        # 正确捕获业务逻辑异常并记录日志。
        logging.info('start')
        po = Page2(driver)
        try:
            po.a3mall_dingdan_002()
        except TimeoutError as e:
            print(e)
        logging.info('last')

    # 实现通用异常处理机制。
    def test_a3mall_login_003(self, driver):
        # 正确捕获业务逻辑异常并记录日志。
        logging.info('start')
        po = Page2(driver)
        try:
            po.a3mall_dingdan_002()
        except Exception as e:
            print(e)
        logging.info('last')

    # 正确抛出业务逻辑异常（如订单不存在或权限不足）。
    def test_a3mall_login_004(self, driver):
        # 正确捕获业务逻辑异常并记录日志。
        logging.info('start')
        po = Page2(driver)
        try:
            po.a3mall_dingdan_002()!=None
        except Exception as e:
            print(e)
        logging.info('last')

if __name__ == '__main__':
    pytest.main()